package com.imooc.alllearning.exception;

import lombok.Getter;

/**
 * 业务类异常
 * @Author: crowsjian
 * @Date: 2020/3/30 20:44
 */
public class BusinessException extends RuntimeException {

    //异常编码
    @Getter
    private final String code;

    /**
     * 更具枚举构造业务类异常
     * @param errorCodeEnum
     */
    public BusinessException(ErrorCodeEnum errorCodeEnum){
        super(errorCodeEnum.getMessage());
        this.code = errorCodeEnum.getCode();
    }

    /**
     * 自定义消息体 构造业务类异常
     * @param errorCodeEnu
     * @param message
     */
    public BusinessException(ErrorCodeEnum errorCodeEnu, String message){
        super(message);
        this.code = errorCodeEnu.getCode();
    }

    /**
     * 根据异常构造业务类异常
     * @param errorCodeEnu
     * @param cause
     */
    public BusinessException(ErrorCodeEnum errorCodeEnu, Throwable cause){
        super(cause);
        this.code = errorCodeEnu.getCode();
    }
}
